﻿using JinfuyuanProject.Entity;

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace JinfuyuanProject.Repository
{
    public class PackageRepository:IPackageRepository
    {
        private readonly JinfuyuanDbContext _db;
        public PackageRepository(JinfuyuanDbContext db)
        {
            _db = db;
        }

        public bool Delete(Package package)
        {
            _db.Entry(package).State = System.Data.Entity.EntityState.Deleted;
            return _db.SaveChanges() > 0;
        }

        public IQueryable<Package> GetList()
        {
            return _db.Package;
        }

        public Package GetModel(int Id)
        {
            Package package = _db.Package.Find(Id);
            return package;
        }

        public int Insert(Package package)
        {
            _db.Entry(package).State = System.Data.Entity.EntityState.Added;
            _db.SaveChanges();
            return package.Id;
        }

        public bool Update(Package package)
        {
            _db.Entry(package).State = System.Data.Entity.EntityState.Modified;
            return _db.SaveChanges() > 0;
        }
    }
}
